/*
 * This file is part of "Sorting Thoughts" project.
 *
 * Copyright (c) 2009 Hendrik Ebel
 * All Rights Reserved.
 *
 * Please visit http://code.google.com/p/sorting-thoughts/ for more information.
 *
 * --LICENSE NOTICE--
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; If not, see <http://www.gnu.org/licenses/>.
 * --LICENSE NOTICE--
 */
var Thought = Class.create({

    initialize: function(id, title, content, mDate, vDate, cDate, sDate, imported, favorite, rowStyle){
        this.id = id;
        this.title = title;
        this.content = content;
		
		var now = new Date();
		var localOffset = now.getTimezoneOffset() * 60000;
        
        this.mDate = mDate;
        this.vDate = vDate;
		this.cDate = cDate;
		this.sDate = sDate;
		this.tzOffset = localOffset;
        
        this.createDateText = this.formatDate(this.cDate);
        this.modifiedDateText = this.formatDate(this.mDate);
		this.modifiedDateTextWithPrefix = $L("Modified: ") + this.formatDate(this.mDate);
        this.lastViewDateText = this.formatDate(this.vDate);
		this.lastSyncDateText = this.formatDate(this.sDate);
		
		this.longCreateDateText = this.formatDateFull(this.cDate);
        this.longModifiedDateText = this.formatDateFull(this.mDate);
        this.longLastViewDateText = this.formatDateFull(this.vDate);
		this.longLastSyncDateText = this.formatDateFull(this.sDate);
        
        this.imported = imported;
        this.isFavorite = favorite;
        this.parent = ""; 
		this.rowStyle = rowStyle;
    },
    
    initNewThought: function(){
        var now = new Date();
        var gmtDate = now.getTime();
        var localOffset = now.getTimezoneOffset() * 60000;
        this.id = gmtDate + localOffset; // because of historical reasons plus local is needed 
        this.cDate = gmtDate;
        this.mDate = gmtDate;
        this.vDate = gmtDate;
		this.tzOffset = localOffset;
		
		this.sDate = "";
        this.imported = 0;
        this.isFavorite = 0;
        this.title = "";
        this.content = "";
		this.rowStyle = "whiteColor";
        
        this.createDateText = this.formatDate(this.cDate);
        this.modifiedDateText = this.formatDate(this.mDate);
		this.modifiedDateTextWithPrefix = $L("Modified: ") + this.formatDate(this.mDate);
        this.lastViewDateText = this.formatDate(this.vDate);
        this.lastSyncDateText = this.formatDate(this.sDate);
		
		this.longCreateDateText = this.formatDateFull(this.cDate);
        this.longModifiedDateText = this.formatDateFull(this.mDate);
        this.longLastViewDateText = this.formatDateFull(this.vDate);
		this.longLastSyncDateText = this.formatDateFull(this.sDate);
		
        this.parent = "";
    },
    
    modified: function(title, content){
        var now = new Date();
        var localOffset = now.getTimezoneOffset() * 60000;
        
        this.mDate = now.getTime();
        this.title = title;
        this.content = content;
		this.tzOffset = localOffset;
    },
    
    viewed: function(){
        var now = new Date();
        var localOffset = now.getTimezoneOffset() * 60000;
        
        this.vDate = now.getTime();
		this.tzOffset = localOffset;
    },
    
    formatDate: function(rawDate){
        if (rawDate) {
            var data = new Date(parseFloat(rawDate));
            return Mojo.Format.formatDate(data, "short");
        }
    },
	
	formatDateFull: function(rawDate){
        if (rawDate) {
            var data = new Date(parseFloat(rawDate));
            return Mojo.Format.formatDate(data, "full");
        }
    }
    
});
